package com.ms.education.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ms.education.cms.entity.Banner;
import com.ms.education.cms.entity.BannerGroup;
import com.ms.education.cms.mapper.BannerMapper;
import com.ms.education.cms.service.BannerGroupService;
import com.ms.education.cms.service.BannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author ms
 * @since 2023-01-21
 */
@Service
public class BannerServiceImp extends ServiceImpl<BannerMapper, Banner> implements BannerService {

    @Autowired
    private BannerGroupService bannerGroupService;

    @Override
    public List<Banner> getShowGroupBanners() {
        //找到应该被展示的分组 只能有一个
        QueryWrapper<BannerGroup> wrapper = new QueryWrapper<>();
        wrapper.eq("is_show", true);
        Integer group = bannerGroupService.getOne(wrapper).getId();
        QueryWrapper<Banner> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("group_id", group).orderByAsc("sort");
        return this.list(wrapper1);
    }

    @Override
    public List<Banner> getBannersByGroupId(Integer groupId) {
        QueryWrapper<Banner> wrapper = new QueryWrapper<>();
        wrapper.eq("group_id",groupId).orderByAsc("sort");
        return this.list(wrapper);
    }
}
